<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%@ include file="/WEB-INF/view/commons/common.jsp" %>
<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>光蓝后台管理系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />
    <link rel="stylesheet" href="${ctx}/static/css/font.css">
    <link rel="stylesheet" href="${ctx}/static/css/xadmin.css">
    <link rel="stylesheet" href="https://cdn.bootcss.com/Swiper/3.4.2/css/swiper.min.css">
    <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <script type="text/javascript" src="https://cdn.bootcss.com/Swiper/3.4.2/js/swiper.jquery.min.js"></script>
    <script src="${ctx}/static/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="${ctx}/static/js/xadmin.js"></script>
</head>
<body>
<!-- 中部开始 -->
<div class="wrapper">
    <!-- 右侧主体开始 -->
    <div class="page-content">
        <div class="content">
            <!-- 右侧内容框架，更改从这里开始 -->
            <form class="layui-form" action="/system/user/editUser" id="dataForm">
                <input type="hidden" name="editId" value="${user.id}">
                <div class="layui-form-item">
                    <label for="userName" class="layui-form-label">
                        用户名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="userName" name="userName" required lay-verify="required"
                               autocomplete="off" value="${user.userName}" class="layui-input">
                    </div>
                </div>
                <c:if test="${user.id == null || user.id == ''}">
                    <div class="layui-form-item">
                        <label for="passWord" class="layui-form-label">
                           密码
                        </label>
                        <div class="layui-input-inline">
                            <input type="text" id="passWord" name="passWord" required lay-verify="required"
                                   autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </c:if>
                <div class="layui-form-item">
                    <label for="realName" class="layui-form-label">
                        真实姓名
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="realName" name="realName" required lay-verify="required"
                               autocomplete="off" value="${user.realName}" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="userPhone" class="layui-form-label">
                        手机
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="userPhone" name="userPhone" autocomplete="off" value="${user.userPhone}"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="email" class="layui-form-label">
                        邮箱
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="email" name="email" required lay-verify="email"
                               autocomplete="off" value="${user.email}" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label for="address" class="layui-form-label">
                        地址
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="address" name="address" autocomplete="off" value="${user.address}"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label for="birthday" class="layui-form-label">
                        生日
                    </label>
                    <div class="layui-input-inline">
                        <input type="text" id="birthday" name="birthday" autocomplete="off" value="${user.birthday}"
                               class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <button class="layui-btn" id="formBtn" onclick="submitDataForm();">
                        保存
                    </button>
                </div>
            </form>
            <!-- 右侧内容框架，更改从这里结束 -->
        </div>
    </div>
    <!-- 右侧主体结束 -->
</div>
<!-- 中部结束 -->

<script type="application/javascript">

    function submitDataForm(){
        $.ajax({
            type:'post',
            data:{'editId':$('#editId').val(),
                'userName':$('#userName').val(),
                'passWord':$('#passWord').val(),
                'realName':$('#realName').val(),
                'userPhone':$('#userPhone').val(),
                'email':$('#email').val(),
                'address':$('#address').val(),
                'birthday':$('#birthday').val(),
            },
            url:'/system/user/editUser',
            dataType:'json',
            success:function (data) {
                //添加数据成功，关闭弹出窗之前，刷新列表页面的数据
                parent.window.location.href="/system/user/index";
                var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
                parent.layer.close(index);
            },
            error:function (error) {
                layer.msg(error.msg,{icon:1,time:1000})
            }
        });
    }


    layui.use(['laydate'], function(){
        laydate = layui.laydate;//日期插件
        var birthday = {
            min: laydate.now(),
            max: '2099-06-16 23:59:59',
            istoday: false
        };
        document.getElementById('birthday').onclick = function(){
            birthday.elem = this;
            laydate(birthday);
        };
    });
</script>
</body>
</html>